package library;

import java.util.ArrayList;
import java.util.List;

import library.item.Book;
import library.item.ItemCategory;
import library.item.Journal;
import library.item.LibraryItem;
import library.item.Map;
import library.item.Movie;

public class ExtendedLibrary<T extends LibraryItem> extends BasicLibrary<T>
		implements CategorizedLibrary<T> {

	public void putAll(BasicLibrary<T> lib) {
		for (T value : lib.getLibrary().values()) {
			this.addEntry(value);
		}
	}

	@Override
	public List<T> getElementsByCategory(ItemCategory category) {
		List<T> list = new ArrayList<T>();
		switch (category) {
		case PRINTED:
			for (T value : library.values()) {
				if (value.getClass().equals(Book.class)
						|| (value.getClass().equals(Journal.class))
						|| (value.getClass().equals(Map.class)))
					list.add(value);
			}
			return list;
		case SCIENTIFIC:
			for (T value : library.values()) {
				if (value.getClass().equals(Book.class)
						|| value.getClass().equals(Journal.class))
					list.add(value);
			}
			return list;
		case LEISURE:
			for (T value : library.values()) {
				if (value.getClass().equals(Map.class)
						|| value.getClass().equals(Movie.class))
					list.add(value);
			}
			return list;
		case ANY:
			for (T value : library.values()) {
				list.add(value);
			}
			return list;
		default:
			return list;
		}
	}

}
